Skip to content

[configparser] Narrow RawConfigParser.popitem() to SectionProxy - #16289

Merged
srittau merged 1 commit into
python:mainfrom
advitrocks9:configparser-popitem-sectionproxy
Aug 31, 2026
Merged

[configparser] Narrow RawConfigParser.popitem() to SectionProxy#16289
srittau merged 1 commit into
python:mainfrom
advitrocks9:configparser-popitem-sectionproxy

Conversation

@advitrocks9

Copy link
Copy Markdown
Contributor

Follow-up to #16238, which left this one out.

RawConfigParser never declares popitem(), so it resolves to MutableMapping.popitem with _VT bound to _Section:

cp = configparser.ConfigParser()
cp.read_string("[a]\nx = 1\n")
name, section = cp.popitem()
section.name
error: "Mapping[str, str]" has no attribute "name"  [attr-defined]

At runtime RawConfigParser defines its own popitem, and it returns self[key], which __getitem__ already declares as SectionProxy. __getitem__, items() and values() are all narrowed the same way.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@advitrocks9

Copy link
Copy Markdown
Contributor Author

Anything needed on this? CI is green and primer-clean.

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau

srittau commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Anything needed on this? CI is green and primer-clean.

Just maintainer time, which is unfortunately very limited.

@srittau
srittau merged commit 3881f1f into python:main Aug 31, 2026
88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants